package com.aqian.theme.color.happy.ui.screens.profile

import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.*
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.unit.dp

@Composable
fun ProfileScreen(
    modifier: Modifier = Modifier
) {
    LazyColumn(
        modifier = modifier.fillMaxSize(),
        contentPadding = PaddingValues(16.dp)
    ) {
        // 用户信息
        item {
            UserInfoSection()
            Spacer(modifier = Modifier.height(24.dp))
        }

        // 我的主题
        item {
            MyThemesSection()
            Spacer(modifier = Modifier.height(24.dp))
        }

        // 功能列表
        item {
            FeaturesSection()
            Spacer(modifier = Modifier.height(24.dp))
        }

        // 设置列表
        item {
            SettingsSection()
        }
    }
}

@Composable
fun UserInfoSection() {
    Card(
        modifier = Modifier.fillMaxWidth()
    ) {
        Row(
            modifier = Modifier
                .fillMaxWidth()
                .padding(16.dp),
            verticalAlignment = Alignment.CenterVertically
        ) {
            // 头像
            Box(
                modifier = Modifier
                    .size(64.dp),
                contentAlignment = Alignment.Center
            ) {
                Text("头像")
            }
            
            Spacer(modifier = Modifier.width(16.dp))
            
            // 用户信息
            Column {
                Text(
                    text = "用户名",
                    style = MaterialTheme.typography.titleMedium
                )
                Text(
                    text = "查看个人主页 >",
                    style = MaterialTheme.typography.bodyMedium
                )
            }
        }
    }
}

@Composable
fun MyThemesSection() {
    Card(
        modifier = Modifier.fillMaxWidth()
    ) {
        Column(
            modifier = Modifier.padding(16.dp)
        ) {
            Text(
                text = "我的主题",
                style = MaterialTheme.typography.titleMedium
            )
            
            Spacer(modifier = Modifier.height(16.dp))
            
            Row(
                modifier = Modifier.fillMaxWidth(),
                horizontalArrangement = Arrangement.SpaceEvenly
            ) {
                ThemeStatItem(title = "上传", count = 0)
                ThemeStatItem(title = "下载", count = 0)
                ThemeStatItem(title = "收藏", count = 0)
            }
        }
    }
}

@Composable
fun ThemeStatItem(
    title: String,
    count: Int
) {
    Column(
        horizontalAlignment = Alignment.CenterHorizontally
    ) {
        Text(
            text = count.toString(),
            style = MaterialTheme.typography.titleLarge
        )
        Text(
            text = title,
            style = MaterialTheme.typography.bodyMedium
        )
    }
}

@Composable
fun FeaturesSection() {
    Card(
        modifier = Modifier.fillMaxWidth()
    ) {
        Column(
            modifier = Modifier.padding(16.dp)
        ) {
            Text(
                text = "功能",
                style = MaterialTheme.typography.titleMedium
            )
            
            Spacer(modifier = Modifier.height(16.dp))
            
            features.forEach { feature ->
                FeatureItem(
                    icon = feature.icon,
                    title = feature.title,
                    onClick = {}
                )
            }
        }
    }
}

@Composable
fun FeatureItem(
    icon: ImageVector,
    title: String,
    onClick: () -> Unit
) {
    Row(
        modifier = Modifier
            .fillMaxWidth()
            .padding(vertical = 8.dp),
        verticalAlignment = Alignment.CenterVertically
    ) {
        Icon(
            imageVector = icon,
            contentDescription = title,
            tint = MaterialTheme.colorScheme.primary
        )
        
        Spacer(modifier = Modifier.width(16.dp))
        
        Text(
            text = title,
            style = MaterialTheme.typography.bodyLarge,
            modifier = Modifier.weight(1f)
        )
        
        Icon(
            imageVector = Icons.Default.KeyboardArrowRight,
            contentDescription = "更多"
        )
    }
}

@Composable
fun SettingsSection() {
    Card(
        modifier = Modifier.fillMaxWidth()
    ) {
        Column(
            modifier = Modifier.padding(16.dp)
        ) {
            Text(
                text = "设置",
                style = MaterialTheme.typography.titleMedium
            )
            
            Spacer(modifier = Modifier.height(16.dp))
            
            settings.forEach { setting ->
                FeatureItem(
                    icon = setting.icon,
                    title = setting.title,
                    onClick = {}
                )
            }
        }
    }
}

// 数据模型
data class Feature(
    val icon: ImageVector,
    val title: String
)

// 示例数据
private val features = listOf(
    Feature(Icons.Default.Download, "下载管理"),
    Feature(Icons.Default.Favorite, "我的收藏"),
    Feature(Icons.Default.History, "浏览历史"),
    Feature(Icons.Default.Star, "我的评分")
)

private val settings = listOf(
    Feature(Icons.Default.Settings, "通用设置"),
    Feature(Icons.Default.Notifications, "通知设置"),
    Feature(Icons.Default.Security, "隐私设置"),
    Feature(Icons.Default.Info, "关于我们")
)
